# -*- coding:utf-8 -*-
import os,sys
import re
import traceback
import time
from datetime import datetime
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir))
import supeanut_config
from CommonLib.mylog import mylog
from DataSupport.SinaDayDataSupport import SinaDayDataSupport
from CommonLib.StockTool import StockTool


'''
作者：supeanut
创建时间：2016-xx-xx xx:xx:xx
功能描述：
	xxx
	xxxxx
相关配置：
	supeanut_config.XXX
历史改动：
	2016-xx-xx: xxxxxx
'''
class SinaMin2Day:
	# init what
	def __init__(self):
		self.obj = SinaDayDataSupport()

	def process(self):
		today = datetime.today()
		date = today.strftime('%Y-%m-%d')
		# 判断交易日
		stocktool_obj = StockTool()
		flag, all_trade_date = stocktool_obj.get_trade_date()
		if flag is False:
			return False, 'get trade date faild'
		if date not in all_trade_date:
			return True, 'not trade date'
		# 0容错模式
		flag, msg =self.obj.extract(date, False)
		if flag is False:
			return False, msg
		# 验证并格式化数据
		flag, msg = self.obj.verify(msg)
		if flag is False:
			return False, msg
		# 保存到csv
		flag, msg = self.obj.store(msg, date)
		if flag is False:
			return False, msg
		return True, 'suc'



if __name__ == '__main__':
	obj = SinaMin2Day()
	print obj.process()
